If Else Conditional Statement In Siemens Wincc Vbscript

Published on Dec21, 2024 | Category: tia wincc
Share this article:

A conditional statement in vbscript is used to perform different task or action which base on a specified condition is true or false. an if else is conditional statement which execute task or action if condition is true otherwise else condition is executed. you can use multiple if else statement within vbscript. The condition of if else statement is an expression with Boolean value (TRUE or FALSE). Logical expression or comparative expressions can be stated as conditions. When the if else condition is executed, the stated expressions are evaluated. If the value of an expression is TRUE, the if task is executed otherwise else task is executed.

If Then conditional statements in wincc vbscript

if then conditional statement execute task if condition of if statement is true. following are the expression of If then conditional statement in wincc hmi vbscript

img/wincc if else statement/If Then conditional statements in wincc vbscript.webp

above is the example of if then conditional statement in wincc vbscript. in this example we have two input output field which associated with tag1 and tag2 and when button pressed events evaluates if condition. If the condition is true then statement executed. Condition for this example is to evaluate value of both input output fields if the value are equal than textfild1 text changed to both values are equal. following are code explanation

If Then else conditional statements in wincc vbscript

if then else statement in VBScript is used to perform conditional checks and execute specific blocks of code based on the result of the condition. if the condition is true then if statement is executed if the condition is false then else condition is executed following are the expression of if then else conditional statement in wincc vbscript

wincc vbscript example of if then else conditional statment

below is the example of if then else conditional statement in wincc vbscript. in this example compare two input output fields value when button is pressed if the values are equal then text field text changed to "values are equal otherwise else statement is executed and text field text changed to "both values are not equal". tag1 and tag2 are associated with both input output field.

img/wincc if else statement/wincc vbscript example of if then else conditional statment.webp

following are the code explanation

how it works
  1. The values of two SmartTags (tag1 and tag2) are retrieved and stored in variables.
  2. It sets a reference to the text field object on a specific screen.
  3. A conditional check is performed to see if the two values are equal.
  4. If the values are equal, the text field displays "Both Values Are Equal".
  5. If the values are not equal, the text field displays "Both Values Are Not Equal".

wincc vbscript multiple if else statement

A multiple If-Else statement evaluates multiple conditions, and if any of the conditions are true, it executes the corresponding block of code. If none of the conditions are true, the Else block is executed. This type of statement is useful when you need to check several conditions based on a single variable or expression and perform different actions depending on the outcome of each condition. It works by sequentially checking each condition. Once a true condition is found, the associated block of code is executed, and the remaining conditions are skipped. If no condition evaluates to true, the Else block is executed as a fallback. following are the expression of multiple if else statement in wincc vbscript

example of multiple if else statement in wincc vbscript

below is the multiple if else statement in wincc vbscript. in this script compare two value. comperison result depend on condition. value1 and value 2 is associated with tag 1 and tag 2. tag 1 and tag2 are tag for input output fields. condition is executed when button is pressed.

img/wincc if else statement/example of multiple if else statement in wincc vbscript.webp

The script compares two values and uses conditional statements (If-Else) to execute different blocks of code based on their relationship. Below is a breakdown of the code: